<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>分类列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
	<link rel="stylesheet" href="/style/list.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:100px;">
                    <select name="supplier" id="supplier"  lay-verify="required" lay-filter="select1">

                    </select>
                </div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-admin" data-type="add" onclick="exportOrder()" id="exportOrder">导单</button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">

            <table class="layui-hide" id="test"></table>
			
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" data="{{d.url}}" onclick="getUrl(this);">下载</a>
            </script>

        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<script src="/layui/jquery.min.js"></script>
<style>
    .layui-body{overflow-y: scroll;}	
	.laytable-cell-1-orderId{width:50px;}
</style>
<script type="text/javascript">
    var tip_index = 0;  
	function show(e)
	{
		tip_index = layer.tips($("#orderGoos"+e).html(), "#order"+e, {tips: [2, '#ddd'],time: 0,area: ['300px', 'auto'],});
	}
</script>
<script>
    $(function () {
        var timer = setInterval(function(){sear()},3000);
        var urls="/goods?url=export%2FselectSupplier";
        $.ajax({
            url: urls,
            type: "GET",
            async:false,
            dataType: "json", //指定服务器返回的数据类型
            success: function(result) {
                if(result.code=="000000"){
                    var ss="";
                    ss +="<option   value='-1'>导全部</option>";
                    $.each(result.data, function(i, item){
                        //alert(item.suppliernoid);
                        if(item.suppliernoid==1000){
                            //alert(item.suppliernoid);
                            ss +="<option selected='selected' value='"+item.suppliernoid+"'>"+item.supplier+"</option>";
                        }else {
                            ss +="<option value='"+item.suppliernoid+"'>"+item.supplier+"</option>";
                        }
                    });
                    $("#supplier").append(ss);
                }
            }
        });

        $.ajax({
            url:"/getOrderUrl",
            type:'post',
            dataType: 'json',
            contentType: 'application/json',
            success: function (result) {
                if(result.code=="000000"){
                    var url=result+"export/readExcel?id="+result.count;
                    $("#form1").attr("action",url);
                }else {
                    alert("请登录")
                }
            }
        });
        // <option selected="selected" value="0">订单状态</option>


    });
    function sear() {
        // alert(state);
        if(state==1){
            window.location.reload();
            state=0;
        }
    }
    function getUrl(obj) {
        var fileName=$(obj).attr("data");
        // var pos=fileName.lastIndexOf("\\");
        // var fname=fileName.substring(pos);
        window.location=fileName;
        // $.ajax({
        //     url: '/getDocuments?path='+fileName,
        //     type: 'post',
        //     dataType: 'json',
        //     contentType: 'application/json',
        //     async: false,
        //     success: function(data){
        //
        //     }
        // });
        //$.get("http://127.0.0.1/export/getUrl?path="+fileName);
    };
    var state=0;
    function exportOrder() {
        //window.location="/Excel";
        $.ajax({
            url: '/goods?url=export%2FexportExcel?supid='+$("#supplier").val(),
            type: 'post',
            // dataType: 'json',
            // contentType: 'application/json',
            async: false,
            success: function(data){
                // alert(data);
                state=1;
            }
        });
    }
    var table;
    layui.use('table', function(){
        table = layui.table
            ,form = layui.form;

        table.render({
            elem: '#test'
            ,url:'/goods?url=export%2FgetRecordList'
            //,url:'/data/logistics/exportOrder.js'
			,cellMinWidth:80
            ,cols: [[
                {type:'numbers'}
                ,{type: 'checkbox'}
                ,{field:'id',width:60,title:'ID'}
                ,{field:'type', title:'类型'}
				,{field:'number',title:'数量'}
				,{field:'adminname',title:'操作员'}
                ,{field:'supplier',title:'商家'}
				,{field:'time',width:200,title: '导单时间',templet :function (row){return createTime(row.time);}}
				,{field:'url',width:250, title:'下载', templet: '#barDemo', unresize: true}
            ]]
			,page: true
            ,id: 'testReload'
        });

        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });


    });


    function createTime(v){
        return v;
        //return new Date(parseInt(v)).toLocaleString();
    }
    /**重写toLocaleString方法*/
    Date.prototype.toLocaleString = function() {
        var y = this.getFullYear();
        var m = this.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = this.getDate();
        d = d<10?("0"+d):d;
        var h = this.getHours();
        h = h<10?("0"+h):h;
        var M = this.getMinutes();
        M = M<10?("0"+M):M;
        var S=this.getSeconds();
        S=S<10?("0"+S):S;
        return y+"-"+m+"-"+d+" "+h+":"+M+":"+S;}
	
</script>


</body>
</html>